home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- #include <gl.h>
- #include <device.h>
- #include <unistd.h>
- #include "showcaseui.h"
- #include "generic.h"
-
- /* This file implements the message() command that is called in various
- * places to present messages and to ask for confirmation. It happens
- * to use the Showcase libui. If you don't like this code, toss this
- * file out, but provide a routine called message that does the same
- * sorts of things this one does.
- */
-
- static Button *ybut = 0, *nbut = 0, *cbut = 0;
- static long xmin, xmax, ymin, ymax;
-
- extern long uiinited; /* this is declared in pulldown.c */
-
- long owid, newwid;
-
- void createdialogarea()
- {
- long screenx, screeny;
-
- screenx = getgdesc(GD_XPMAX);
- screeny = getgdesc(GD_YPMAX);
- xmin = xsize/2 - 300 + xorg;
- ymin = ysize/2 - 55 + yorg;
- if (xmin < 0) xmin = 0;
- if (xmin + 600 >= screenx) xmin = screenx - 601;
- if (ymin < 0) ymin = 0;
- if (ymin + 110 >= screeny) ymin = screeny - 111;
- xmax = xmin + 600;
- ymax = ymin + 110;
- prefposition(xmin, xmax, ymin, ymax);
- noborder();
- owid = winget();
- newwid = winopen("dialog");
- winset(newwid);
- pushviewport();
- savemat();
- viewport(0, (short)(xmax-xmin), 0, (short)(ymax-ymin));
- ortho2(-0.5, xmax-xmin+0.5, -0.5, ymax-ymin+0.5);
- }
-
- void closedialogarea()
- {
- unlocateall();
- popviewport();
- restoremat();
- winclose(newwid);
- }
-
- static void drawbackground()
- {
- uiWhite(); rectfi(0, 0, xmax-xmin, ymax-ymin);
- setpattern(P_UISHADOW);
- uiVyLtGray(); rectfi(0, 0, xmax-xmin, ymax-ymin);
- setpattern(0);
- uiBlack();
- }
-
- static void drawconfirmmessage(char *s)
- {
- long cheight;
- drawbackground();
- recti(0, 0, 600, 110);
- recti(3, 3, 597, 107);
- recti(4, 4, 596, 106);
- cheight = 80;
- while (*s) {
- char *sptr = s;
- cmov2i(20, cheight); cheight -= 18;
- while (*sptr && *sptr != '\n') sptr++;
- if (*sptr) {
- *sptr = 0; charstr(s); *sptr = '\n'; s = sptr+1;
- } else {
- charstr(s);
- s = sptr;
- }
- }
- if (ybut) drawbut(ybut);
- if (nbut) drawbut(nbut);
- if (cbut) drawbut(cbut);
- swapbuffers();
- }
-
- static void makeconfirmbuts(char *b1, char *b2, char *b3)
- {
- createdialogarea();
- if (ybut) freebut(ybut); ybut = 0;
- if (nbut) freebut(nbut); nbut = 0;
- if (cbut) freebut(cbut); cbut = 0;
- if (b1) {
- ybut = newbut(100, 15, 170, 45);
- loadbut(ybut, b1);
- }
- if (b2) {
- nbut = newbut(200, 15, 270, 45);
- loadbut(nbut, b2);
- }
- if (b3) {
- cbut = newbut(300, 15, 370, 45);
- loadbut(cbut, b3);
- }
- }
-
- long message(char *str, char *b1, char *b2, char *b3)
- {
- short val;
- long dev, mx, my;
- static inited = 0;
-
- if (!uiinited) {
- uiinited = 1;
- initui();
- }
- if (inited == 0) {
- inited = 1;
- initbut();
- }
- makeconfirmbuts(b1, b2, b3);
- drawconfirmmessage(str);
- if (ybut == 0) {
- (void)sleep(2);
- closedialogarea();
- return 0;
- }
- while (1) {
- dev = qread(&val);
- switch (dev) {
- case 0:
- break;
- case MOUSEX:
- case MOUSEY:
- mx = getvaluator(MOUSEX) - xmin;
- my = getvaluator(MOUSEY) - ymin;
- if (ybut) locatebut(ybut, mx, my);
- if (nbut) locatebut(nbut, mx, my);
- if (cbut) locatebut(cbut, mx, my);
- break;
- case LEFTMOUSE:
- if (val == 0) break;
- mx = getvaluator(MOUSEX) - xmin;
- my = getvaluator(MOUSEY) - ymin;
- if (ybut && inbut(ybut, mx, my))
- if (pressbut(ybut, mx, my)) {
- closedialogarea();
- return 1;
- }
- if (nbut && inbut(nbut, mx, my))
- if (pressbut(nbut, mx, my)) {
- closedialogarea();
- return 2;
- }
- if (cbut && inbut(cbut, mx, my))
- if (pressbut(cbut, mx, my)) {
- closedialogarea();
- return 3;
- }
- break;
- case REDRAW:
- winpop();
- drawconfirmmessage(str);
- break;
- case WINQUIT:
- case WINSHUT:
- closedialogarea();
- return 0;
- default:
- if (dev == MOUSEX || dev == MOUSEY) break;
- drawconfirmmessage(str);
- break;
- }
- }
- }
-
-